/**
 * 
 */
package ma.hamada.model;

import javax.swing.event.EventListenerList;

import ma.hamada.Listener.PieceListener;
import ma.hamada.event.PositionChangedEvent;

/**
 * @author m.abdelouhab
 * 
 */
public class PieceModel {
	
	/*
	 * 
	 */
	private EventListenerList listeners;

	/*
	 * 
	 */
	private String value;

	/*
	 * 
	 */
	private PiecePosition position;
	
	

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @return the position
	 */
	public PiecePosition getPosition() {
		return position;
	}

	/**
	 * @param position
	 *            the position to set
	 */
	public void setPosition(PiecePosition position) {
		this.position = position;
		firePiecePositionChanged();
	}
	
	public void addPiecePositionListener(PieceListener listener){
		listeners.add(PieceListener.class, listener);
	}
	
	public void removePiecePositionListener(PieceListener pl){
		 listeners.remove(PieceListener.class, pl);
	}
	
	public void firePiecePositionChanged(){
		PieceListener[] listenerList = (PieceListener[])listeners.getListeners(PieceListener.class);
		
		for(PieceListener listener : listenerList){
			listener.positionChanged(new PositionChangedEvent(this, getPosition()));
		}
	}

	/**
	 * @param value
	 */
	public PieceModel(String value) {
		this.value = value;
		listeners = new EventListenerList();
	}

}
